package helper

import (
	"regexp"
	"strings"
)

/*
	This function return array tag by name from html content.
*/

func GetTagByName(htmlContent string, tagName string) (arrayTag []string) {
	if strings.EqualFold(tagName, "img") {
		re := regexp.MustCompile("<img(\\s+.*?)(?:src\\s*=\\s*(?:'|\")(.*?)(?:'|\"))(\\/?)>")
		arrayTag = re.FindAllString(htmlContent, -1)
	} else if strings.EqualFold(tagName, "a") {
		re := regexp.MustCompile("<a[^>]*>(.*?)</a>")
		arrayTag = re.FindAllString(htmlContent, -1)
	}
	return
}

/*
	This function return value of an atribute from tag
*/
func GetAttributeFromTag(tag string, attribute string) (value string) {
	regexStr := attribute + "\\s*=\\s*\"(.+?)\""
	re := regexp.MustCompile(regexStr)
	arrayV := re.FindAllString(tag, -1)
	if len(arrayV) > 0 {
		value = arrayV[0]
		value = strings.Replace(value, attribute+"=", "", -1)
		value = strings.Replace(value, "\"", "", -1)
	}
	return
}

/*
	This function return html element by id
*/

func GetElementById(htmlContent string, id string) (elementArray []string) {
	
	return
}

/*
	This function return html element by class
*/

func GetElementByClass(htmlContent string, id string) (elementArray string) {
	return
}
